exports.GAMoveTo = Core.Class.subclass({
    classname: 'GAMoveTo',
    
    initialize: function(node, time, endPosition, callback, intervalCallback) {
		this._callback = callback;
		this._node = node;
		this._startPosition = new Core.Point(node.getPosition().getX(), node.getPosition().getY());
		this._endPosition = endPosition;
		this._delta = new Core.Point(this._endPosition.getX() - this._startPosition.getX(), this._endPosition.getY() - this._startPosition.getY());
		this._duration = time;
		this._intervalCallback = intervalCallback;
	},
	runAction: function() {
		this._timer = setTimeout(this.update.bind(this, 0), 100);
	},
	update: function(t) {		
		if(t < this._duration) {
			t += 100;
			this.updateAction(Math.min(t/this._duration,1));
			if(this._intervalCallback != null) {
				this._intervalCallback();
			}
			this._timer = setTimeout(this.update.bind(this, t), 100);
		}
		else {
			if(this._callback){
				this._callback();
			}
			else {
				this.stopAction();
			}
		}
	},
	updateAction: function(dT) {
		this._node.setPosition(new Core.Point(this._startPosition.getX() + this._delta.getX() * dT, this._startPosition.getY() + this._delta.getY() * dT));
	},
	/*update: function(t, dT) {
		t += 100;
		this._node.setPosition(new Core.Point(this._startPosition.getX() + this._delta.getX() * dT, this._startPosition.getY() + this._delta.getY() * dT));
		if(t < this._duration) {
			this._timer = setTimeout(this.update.bind(this, t, t/this._duration), 100);
		}
		else {
			console.log("update: endPos"+ this._endPosition.getX() +"-"+this._endPosition.getY());
			console.log("update: nodePos" + this._node.getPosition().getX()+ "-"+this._node.getPosition().getY());
			this._callback();
			//this.destroy();
		}
	},*/
	stopAction: function() {
		 clearTimeout(this._timer);
		 this.destroy();
	},
	destroy: function() {
		delete this._startPosition;
		delete this._delta;
	}
});